import { createRouter } from 'vue-router'
import { createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '',
    component: () => import('./layouts/Layout.vue'),
    redirect: '/home',
    children: [
      { path: '/home', component: () => import('./pages/Home.vue') },
      { path: '/storeProject', component: () => import('./pages/store/Project.vue') },
      { path: '/storeMaterial', component: () => import('./pages/store/Material.vue') }
    ]
  },
  { path: '/login', component: () => import('./pages/Login.vue') },
  { path: '/register', component: () => import('./pages/Register.vue') },
  { path: '/updater', component: () => import('./pages/Updater.vue') }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, _from, next) => {
  const currentPath = to.path
  console.log('currentPath = ' + currentPath)
  /* if (currentPath !== '/login' && currentPath !== '/register') {
    const token = sessionStorage.getItem('token')
    if (token) {
      console.log(1)
      next()
    } else {
      console.log(2)
      next('/login')
    }
  } else {
    console.log(3)
    next()
  } */
    next()
})

export default router
